package com.brightworks.scripthelper.analyzers
{
    import com.brightworks.scripthelper.constants.LineTypeConstants;
    import com.brightworks.scripthelper.constants.MiscConstants;
    import com.brightworks.util.Log;
    import com.brightworks.util.Utils_String;

    public class LineTypeAnalyzer_Chunk_TargetLanguage extends LineTypeAnalyzer
    {
        private static const LINE_CHAR_COUNT_HARD_LIMIT:int = 20;
        private static const LINE_CHAR_COUNT_RECCOMENDED_LIMIT:int = 15;
        private static const LINE_CHAR_COUNT_SOFT_LIMIT:int = 16;

        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
        //
        //          Getters & Setters
        //
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

        public static function get lineTypeDescription():String
        {
            return LineTypeConstants.LINE_TYPE_DESCRIPTION__CHUNK__TARGET_LANGUAGE;
        }

        public static function get lineTypeId():String
        {
            return LineTypeConstants.LINE_TYPE_ID__CHUNK__TARGET_LANGUAGE;
        }

        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
        //
        //          Public Methods
        //
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

        public function LineTypeAnalyzer_Chunk_TargetLanguage()
        {
            super();
            bIsChunkLine = true;
        }

        override public function getProblemReports():Array
        {
            var problemList:Array = [];
            var chineseCharCount:int = Utils_String.getCommonChineseCharacterCount(lineText, true);
            var ratio:Number = chineseCharCount/lineText.length;
            if (ratio < .1)
                problemList.push("Based on its position in its chunk, this line should be a " + LineTypeConstants.LINE_TYPE_DESCRIPTION__CHUNK__TARGET_LANGUAGE + ", and should only contain Chinese characters. This line only contains " + chineseCharCount + " Chinese characters out of " + lineText.length + " characters in this line. " + MiscConstants.IGNORE_PROBLEMS__USE_COMMENT_FOR_EXCEPTIONS_SENTENCE);
            var nonChinesePunctuationString:String = Utils_String.extractCharsFromString(MiscConstants.NON_CHINESE_PUNCTUATION_LIST, lineText);
            if (nonChinesePunctuationString.length > 0)
            {
                var problemString:String = "Based on its position in its chunk, this line should be a " + LineTypeConstants.LINE_TYPE_DESCRIPTION__CHUNK__TARGET_LANGUAGE + ", and should use mainly hanzi-style punctuation.\n";
                problemString += "The following western-style punctuation mark(s) should be replaced with hanzi-style punctuation marks in this line:  " + nonChinesePunctuationString + "\n";
                problemString += "Here, for your reference, are our rules on which punctuation marks to use in which lines:\n";
                problemString += MiscConstants.CHINESE_PUNCTUATION_RULES;
                problemList.push(problemString);
            }
            else
            {
                // We don't have western-style punctuation, so now we check the
                // hanzi-style punctuation.
                if (lineText.indexOf("…") != lineText.indexOf("……"))
                {
                    problemList.push("Based on its position in its chunk, this line should be a " + LineTypeConstants.LINE_TYPE_DESCRIPTION__CHUNK__TARGET_LANGUAGE + ". In these lines ellipses should be made up of two Chinese ellipsis characters (……). This line contains a single Chinese ellipsis character, which is feeling very lonely." );
                }
                else
                {
                    if (!Utils_String.doesStringEndWithString(lineText, ["。", "？", "！", "……", "。）", '。"', "！）", '！"', "？）", '？"', "。”", "？”", "！”", "》", "："]))
                        problemList.push("Based on its position in its chunk, this line should be a " + LineTypeConstants.LINE_TYPE_DESCRIPTION__CHUNK__TARGET_LANGUAGE + ". These lines should usually end with either a period, a question mark or an exclamation mark, or else should end with an ellipsis. This line doesn't end with any of these things.");
                }
            }
            var chineseNonPunctuationCharCount:int = Utils_String.getCommonChineseCharacterCount(lineText, false);
            if (chineseNonPunctuationCharCount > LINE_CHAR_COUNT_HARD_LIMIT)
            {
                problemList.push("Based on its position in its chunk, this line should be a " + LineTypeConstants.LINE_TYPE_DESCRIPTION__CHUNK__TARGET_LANGUAGE + ", and should usually contain a maximum of " + LINE_CHAR_COUNT_RECCOMENDED_LIMIT + " Chinese characters, and *rarely* contain more than " + LINE_CHAR_COUNT_HARD_LIMIT + ". This line contains " + chineseNonPunctuationCharCount + ". Is there some way to break this chunk up into multiple chunks? " + MiscConstants.IGNORE_PROBLEMS__USE_COMMENT_FOR_EXCEPTIONS_SENTENCE);
            }
            else if (chineseNonPunctuationCharCount > LINE_CHAR_COUNT_SOFT_LIMIT)
            {
                problemList.push("Based on its position in its chunk, this line should be a " + LineTypeConstants.LINE_TYPE_DESCRIPTION__CHUNK__TARGET_LANGUAGE + ", and should usually contain a maximum of " + LINE_CHAR_COUNT_RECCOMENDED_LIMIT + " Chinese characters. This line contains " + chineseNonPunctuationCharCount + ". Is there some way to break this chunk up into multiple chunks? " + MiscConstants.IGNORE_PROBLEMS__USE_COMMENT_FOR_EXCEPTIONS_SENTENCE);
            }
            return constructFullProblemStrings(problemList);
        }

        public static function isLineThisType(lineString:String, lineStringList:Array=null, lineNum:int=-1):Boolean
        {   
            // We use another, external, method to determine this at this point, so this method isn't used.
            Log.fatal("LineTypeAnalyzer_Chunk_TargetLanguage.isLineThisType(): Method not implemented");
            return false;
        }

        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
        //
        //          Private Methods
        //
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

    }
}

